<template>
    <div class="login-container">
        <div class="login-box">
            <div class="login-main">
                <h1>您好，欢迎使用长三角车生活</h1>
                <p>权威第三方，买卖更安心</p>
                <el-form
                    ref="ruleFormRef"
                    :inline="true"
                    :model="data.account"
                    :rules="data.rules"
                    label-position="top"
                >
                    <el-form-item label="" prop="name" class="login-input">
                        <el-input v-model="data.account!.name" placeholder="请输入账号">
                            <template #prefix>
                                <el-icon class="el-input__icon"><User /></el-icon> </template
                        ></el-input>
                    </el-form-item>
                    <el-form-item label="" prop="password" class="login-input">
                        <el-input
                            v-model="data.account!.password"
                            placeholder="请输入密码"
                            type="password"
                            show-password
                        >
                            <template #prefix>
                                <el-icon class="el-input__icon"><Lock /></el-icon>
                            </template>
                        </el-input>
                    </el-form-item>
                    <el-form-item label=" " class="login-input">
                        <el-button type="primary" style="width: 100%" @click="data.onSubmit(ruleFormRef)"
                            >登录</el-button
                        >
                    </el-form-item>
                </el-form>
            </div>
        </div>
        <div class="login-poster"></div>
    </div>
</template>

<script lang="ts" setup>
import { reactive, ref, onMounted, onBeforeUnmount } from 'vue'
import type { FormInstance } from 'element-plus'
import LoginData from './index'

/**
 * 表单form
 */
const ruleFormRef = ref<FormInstance>()

/**
 * 初始化数据
 */
const data = reactive(new LoginData())

/**
 * 监听按键抬起
 * @param e
 */
const onKeyUp = async (e: KeyboardEvent) => {
    if (e.key === 'Enter') {
        data.onSubmit(ruleFormRef.value)
    }
}

/**
 * 页面挂载完成
 */
onMounted(() => {
    window.addEventListener('keyup', onKeyUp, false)
})

/**
 * 页面卸载前
 */
onBeforeUnmount(() => {
    window.removeEventListener('keyup', onKeyUp, false)
})
</script>

<style scoped lang="scss">
.login-container {
    width: 100%;
    height: 100%;
    display: flex;
    background-color: #fff;
    .login-box {
        width: 58%;
        height: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
        .login-main {
            width: 60%;
            min-width: 200px;
            h1 {
                font-size: 40px;
                font-weight: 600;
            }
            p {
                font-size: 18px;
                margin-top: 40px;
                margin-bottom: 60px;
            }
        }
    }
    .login-poster {
        width: 42%;
        height: 100%;
        background-image: url('../../assets/images/picture_dlydt.png');
        background-size: cover;
        background-position: center;
    }
}

.el-form--inline.el-form--label-top .el-form-item {
    margin-right: 0;
}
</style>
